import { connect } from '../../vendors/weapp-redux.js'
import { fetchAvatar, fetchUserInfo } from '../../redux/models/personal-info.js'
import CardHead from '../../components/business-card-button-head/business-card-button-head.js'

let pageConfig = {
  data: {
    list: [
      {
        cardData: {
          name: '王俊森',
          title: '项目管理',
          introduction: '善于项目管理，大数据分析之神，架构师，IT行业投资顾问，总之上面都是瞎扯的。',
          style: '',
          avatar: '../../images/avatar.jpg'
        },
        cardHeadData: CardHead.defaultData
      },
      {
        cardData: {
          name: '王俊森2',
          title: '项目管理',
          introduction: '善于项目管理，大数据分析之神，架构师，IT行业投资顾问，总之上面都是瞎扯的。',
          style: '',
          avatar: '../../images/avatar.jpg'
        },
        cardHeadData: CardHead.defaultData
      },
      {
        cardData: {
          name: '王俊森3',
          title: '项目管理',
          introduction: '善于项目管理，大数据分析之神，架构师，IT行业投资顾问，总之上面都是瞎扯的。',
          style: '',
          avatar: '../../images/avatar.jpg'
        },
        cardHeadData: CardHead.defaultData
      }
    ]
  },

  onReady: function() {
    const _this = this
    setTimeout(() => {
      _this.fetchUserInfo()
    }, 1000)
  },

  handYourCard(index) {
    const list = this.data.list
    list[index].cardHeadData = {
      status: 'handed',
      text: '已递交'
    }
    this.setData({
      list
    })
  },
  handCard(event) {
    const index = event.target.dataset.index
    const infoReady = wx.getStorageSync('infoReady')
    if (infoReady) {
      this.handYourCard(index)
    } else {
      wx.showModal({
        title: '提示',
        content: '先到个人中心建立名片，再开始递交名片吧。',
        showCancel: false,
        confirmText: '知道了',
        confirmColor: '#00c200',
        success: function(res) {
          wx.navigateTo({
            url: '/pages/my-business-card/my-business-card'
          })
        }
      })
    }
  }
}

let mapStateToData = state => {
  return {
  }
}

let mapDispatchToPage = dispatch => ({
  fetchAvatar: avatar => dispatch(fetchAvatar(avatar)),
  fetchUserInfo: () => dispatch(fetchUserInfo())
})

pageConfig = connect(mapStateToData, mapDispatchToPage)(pageConfig)
Page(pageConfig)
